//
//  DDHudHelper.m
//  hnGovernment
//
//  Created by zhn on 2017/3/10.
//  Copyright © 2017年 安仔. All rights reserved.
//

#import "DDHudHelper.h"
#import "SVProgressHUD.h"

@implementation DDHudHelper
+ (void)showHudWithResult:(id)result resultSuccess:(resultSuccessBlock)success{
    if(result == nil || [result isKindOfClass:[NSString class]]) {
        [SVProgressHUD showErrorWithStatus:@"服务器错误,请稍后重试"];
        return;
    }
    int resultCode = [result[@"resultCode"] intValue];
    if (resultCode == 0) {
        if (success) {
            dispatch_async(dispatch_get_main_queue(), ^{
                success();
            });
        }
    }else {
        NSString *errorString = result[@"errorDetail"];
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD showErrorWithStatus:errorString];
        });
    }
}

+ (void)showHudWithSuccess:(id)result resultSuccess:(resultSuccessBlock)success {
    if(result == nil)return;
    if ([result isKindOfClass:[NSString class]]) {return;}
    int successValue = [result[@"success"] intValue];
    if (successValue == 1) {
        if (success) {
            dispatch_async(dispatch_get_main_queue(), ^{
                success();
            });
        }
    }else {
        NSString *errorString = result[@"errorDetail"];
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD showErrorWithStatus:errorString];
        });
    }


}

@end
